package com.woniu.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.dao.RbacPermDao;
import com.woniu.entity.RbacPerm;
import com.woniu.entity.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author WenXin
 * @version 1.0
 * @description: TODO
 * @date 2022/9/3 12:52
 */
@Service
public class RbacPermServiceImpl implements RbacPermService {
    @Autowired
    RbacPermDao rbacPermDao;

    @Override
    public ResponseEntity findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<RbacPerm> all = rbacPermDao.findAll();
        PageInfo<RbacPerm> rbacPermPageInfo = new PageInfo<>(all);
        return new ResponseEntity(200, "初始化查询成功", rbacPermPageInfo);
    }

    @Override
    public int addOne(RbacPerm rbacPerm) {

        return rbacPermDao.addOne(rbacPerm);
    }

    @Override
    public int deleteById(int id) {
        return rbacPermDao.deleteById(id);
    }

    @Override
    public int update(RbacPerm rbacPerm) {
        return rbacPermDao.update(rbacPerm);
    }

    @Override
    public ResponseEntity searchByPerms(RbacPerm rbacPerm, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<RbacPerm> rbacPerms = rbacPermDao.searchByPerms(rbacPerm);
        PageInfo<RbacPerm> rbacPermPageInfo = new PageInfo<>(rbacPerms);
        return new ResponseEntity(200, "搜索结果如下", rbacPermPageInfo);
    }

    //通过子查询，查询出当前角色对应的权限
    @Override
    public Set<String> findPermBySetRoles(String username) {

        return rbacPermDao.findPermBySetRoles(username);
    }
}
